import react, { useRef } from 'react';
import axios from 'axios'
import { Button, Input } from 'antd'
import { useHistory } from 'umi'

const FetchGetLogin = ({username, password}) => {
  // 1. 后台跨域 2. 没有封装axios baseURL
  return axios.post('http://127.0.0.1:3005/api/login', {
    username,
    password
  })
}

const Login = () => {
  const history = useHistory()
  const username = useRef()
  const password = useRef()
  const inputValue = useRef()

  const handleLoginCLick = async () => {
// http://localhost:3005/api/serarchKey?keywords=%E9%A3%9E

    axios.get('http://localhost:3005/api/serarchKey', {
      params: {
        keywords: inputValue.current.value
      }
    }).then(res => {
      console.log('res:...:', res)
    })

    // const data = await FetchGetLogin({
    //   username: username.current.state.value,
    //   password: password.current.state.value
    // })
    // if (data.data.code === 0) {
    //   localStorage.setItem('token', data.data.token)
    //   history.push('/book/list')
    // } else {
    //   alert('信息不对')
    // }
  }

  return <div>

     <input ref={inputValue}/>


     <Input ref={username} />
     <Input ref={password} />
     <Button onClick={handleLoginCLick}>登陆</Button>
  </div>
}

export default Login;
